﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OnlyMusic.DomainModel.Repositories;
using System.IO;
using EnterApp.Core.IoC;

namespace OnlyMusic.DomainModel.Services
{
    public class SongManagerService : ISongManagerService
    {
        public bool Upload(Entities.Song song, Roles.IUploader uploader, byte[] content)
        {
            //----- 获取存储路径
            string location = @".\Music\Songs\";

            //----- 生存存储信息
            Entities.SongStoreInfo songStoreInfo = new Entities.SongStoreInfo(song, uploader, DateTime.Now, location);

            //----- 插入数据库
            ISongStoreInfoRepository songStoreInfoRepository = DependencyResolver.Resolve<ISongStoreInfoRepository>(); ;
            songStoreInfoRepository.Add(songStoreInfo);

            //----- 写入物理存储位置
            File.WriteAllBytes(Path.Combine(location + song.Id.ToString() + ".m4a"), content);

            return true;
        }
    }
}
